/**
 * 
 */
package com.gr.staffpm.widget.dialog.task;

import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import com.gr.staffpm.datatypes.Task;
import com.gr.staffpm.datatypes.User;
import com.gr.staffpm.tasks.model.UserChoiceRenderer;


/**
 * @author Graham Rhodes 12 Apr 2011 13:40:36
 */
public abstract class TaskAssignPanel extends Panel {

    private static final long serialVersionUID = 1L;
    private final DropDownChoice<User> teamMembers;
    private final TextArea<String> commentBox;

    public TaskAssignPanel(String id, List<User> team, Task task) {
        super(id);

        Form<Void> form = new Form<Void>("form");

        form.add(teamMembers = new DropDownChoice<User>("teamMembers", new Model<User>(task.getAssignee()), team, new UserChoiceRenderer()));
        teamMembers.setRequired(true);

        commentBox = new TextArea<String>("commentBox", new Model<String>());
        commentBox.setEscapeModelStrings(true);
        commentBox.setOutputMarkupId(true);
        form.add(commentBox);

        form.add(new AjaxButton("submitButton") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                TaskAssignPanel.this.onSubmit(target, commentBox.getValue(), teamMembers.getModelObject());
            }

        });

        form.add(new AjaxButton("cancelButton") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                TaskAssignPanel.this.onCancel(target);
            }

        });
        add(form);
    }

    public abstract void onCancel(AjaxRequestTarget target);

    public abstract void onSubmit(AjaxRequestTarget target, String comment, User user);

}
